﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Business;
using Model;
using System.Web.Security;
using MB.Util;

namespace MvcAppWeb.Controllers
{
    public class PickBatchController : Controller
    {
        //
        // GET: /PickBatch/

        public ActionResult PickBatch()
        {
            if (Session["UserInfo"] == null) return RedirectToAction("LogOn", "Account");
            else
            {
                AppUserList model = (AppUserList)Session["UserInfo"];
                return View(model);
            }
        }

        public JsonResult Query(string BATCHNUMBER, string CheckTimeS)
        {
            int page = int.Parse(Request["page"].ToString());
            int rows = int.Parse(Request["rows"].ToString());
            int total = 0;
            string where = " where 1=1";
            if (!string.IsNullOrEmpty(BATCHNUMBER))
            {
                where += @" and t1.BATCHNUMBER like'%" + BATCHNUMBER + "%'";
            }
            if (!string.IsNullOrEmpty(CheckTimeS))
            {
                where += " and t1.BATCHDATE= '" + CheckTimeS + "'";
            }
            BPickBatch np = new BPickBatch();
            var result = np.GetPickBatchInfoList(page, rows, out total, where);

            Dictionary<string, object> json = new Dictionary<string, object>();
            json.Add("total", total);
            json.Add("rows", result);
            return Json(json, JsonRequestBehavior.AllowGet);
        }

        public string Enable(string batchnumber, string batchdate, int FLAG)
        {

            AppUserList model = (AppUserList)Session["UserInfo"];

            BPickBatch np = new BPickBatch();
          int num=  np.UpdatePickBatchInfo(batchnumber, batchdate, FLAG, model.USERNAME, DateTime.Now);
            if (num>0)
            {
                return "{success:true,msg:'修改成功'}";
            }
            else
            {
                return "{success:false,msg:'修改失败'}";
            }
        }
    }
}
